{r echo=FALSE, message=FALSE, warning=FALSE} # # Initial bin width # initial_binwidth <- 5 # # # Function to create histogram # create_histogram <- function(binwidth) { # ggplot(data = penguins, aes(x = flipper_length_mm)) + # geom_histogram(aes(fill = species), # color = "black", # alpha = 0.5, # position = "identity", # binwidth = binwidth) + # scale_fill_manual(values = c("darkblue", "red", "cyan4")) + # labs(x = "Flipper length (mm)", # y = "Frequency", # title = "Flipper ") + # theme(panel.background = element_rect(fill = "lightgray"), # panel.grid.major = element_line(color = "white", size = 0.5), # panel.grid.minor = element_line(color = "white", size = 0.25)) # } # # # Create initial plot # histogram <- create_histogram(initial_binwidth) # # # Convert ggplot to plotly # histogram_plotly <- ggplotly(histogram) # # # Add slider for bin width # histogram_plotly <- histogram_plotly %>% # layout( # updatemenus = list( # list( # active = 0, # buttons = list( # list( # label = "Bin Width", # method = "update", # args = list(list(visible = c(TRUE, FALSE)), # list(title = "Bin Width", # xaxis = list(title = "Flipper length (mm)"), # yaxis = list(title = "Frequency")))), # list( # label = "5", # method = "update", # args = list(list(visible = c(TRUE, FALSE)), # list(title = "Bin Width", # xaxis = list(title = "Flipper length (mm)"), # yaxis = list(title = "Frequency")), # list(binwidth = 5))), # list( # label = "10", # method = "update", # args = list(list(visible = c(TRUE, FALSE)), # list(title = "Bin Width", # xaxis = list(title = "Flipper length (mm)"), # yaxis = list(title = "Frequency")), # list(binwidth = 10))) # ) # ) # ) # ) # # # Show plot # #histogram_plotly